package com.jxnu.duewang.zmly.zouZhen.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jxnu.duewang.zmly.BR;
import com.jxnu.duewang.zmly.R;
import com.jxnu.duewang.zmly.zouZhen.model.DatabindingDiscoverColumn;

import java.util.List;

/**
 * Project Zmly
 * Author Duewang
 * Time 2016/12/7 0007
 */

public class DiscoverColumnImageAdapter extends PagerAdapter {

    private Context mContext;
    private List<DatabindingDiscoverColumn> mDatabindingDiscoverColumnList;

    public DiscoverColumnImageAdapter(Context context, List<DatabindingDiscoverColumn> databindingDiscoverColumnList) {
        mContext = context;
        mDatabindingDiscoverColumnList = databindingDiscoverColumnList;
    }

    @Override
    public int getCount() {
        int ret=0;
        if (mDatabindingDiscoverColumnList != null&&!mDatabindingDiscoverColumnList.isEmpty()) {
            ret=mDatabindingDiscoverColumnList.size();
        }
        return ret;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View ret = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.discover_column_view_pager, container, true).getRoot();
        ViewDataBinding binding = DataBindingUtil.bind(ret);
        binding.setVariable(BR.discoverColumnList,mDatabindingDiscoverColumnList.get(position));
        return ret;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
    }

    @Override
    public int getItemPosition(Object object) {
        if(getCount()>0){
            return POSITION_NONE;
        }
        return super.getItemPosition(object);
    }
}
